#include"SList.h"

//手动创建一个链表，并打印
void createSList()
{
	//链表是由一个一个的结点组成
	SLTNode* node1 = (SLTNode*)malloc(sizeof(SLTNode));//申请一个结点大小的空间
	//node1 是指针，所以用 -> 引用
	node1->data = 1;
	SLTNode* node2 = (SLTNode*)malloc(sizeof(SLTNode));
	node2->data = 2;
	SLTNode* node3 = (SLTNode*)malloc(sizeof(SLTNode));
	node3->data = 3;
	SLTNode* node4 = (SLTNode*)malloc(sizeof(SLTNode));
	node4->data = 4;

	node1->next = node2;
	node2->next = node3;
	node3->next = node4;
	node4->next = NULL;

	//打印链表，传第一个结点的地址
	SLTPrint(node1);

}



void SListTest01()
{
	SLTNode* plist = NULL;
	//实参plist传给形参phead，形参phead改变后，要影响实参plist，必须传实参plist的地址
	//因此这里要用二级指针来接受一级指针plist
	SLPushBack(&plist, 1);
	SLTPrint(plist);
	SLPushBack(&plist, 2);
	SLPushBack(&plist, 3);
	SLTPrint(plist);

	SLPushFront(&plist, 2);
	SLPushFront(&plist, 3);
	SLTPrint(plist);

	SLPopBack(&plist);
	SLTPrint(plist);
	SLPopBack(&plist);
	SLTPrint(plist);

	SLTNode* find = SLTFind(plist, 3);

	/*
	 if (find == null)
	{
		printf("未找到\n");
	}
	else
	{
		printf("找到了\n");
	} 
	*/

	SLTErase(&plist, find);
	SLTPrint(plist);
	

	
}
int main()
{
	//createSList();
	SListTest01();
	return 0;
}